<?php  if(!defined('PATH_HD')){exit;}
	
	class tag{
	public $tag=array(
		"page"=>array("block"=>0)
		);
	function _new($attr,$content){//新闻显示栏显示
		$catid=isset($attr['cid'])?$attr['cid']:'';//栏目ID
		if(empty($catid)){
			$str="<?php echo '<script>alert(\"请指定cid属性\")</script>'?>";
			return $str;
		}else{
		$db=M('news');
		$row=$db->where("catid='$catid'")->find();
		if($row){
				$titlelen=isset($attr['titlelen'])?$attr['titlelen']:12;
				$limit=isset($attr['row'])?$attr['row']:5;//如果没指定显示行数的话就是默认的5行
					$str='';
				$str.='<?php $db=K("newsview");';
				$str.='$row=$db->field("title,user.username,id,news.catid,cname,news.addtime")->where("hd_news.catid=\''.$catid.'\'")->limit('.$limit.')->all();';
				//$str.='echo "<ul>"';
				$str.='foreach ($row as $field) :
						$id=$field["id"];
						$field["title"]=mb_substr($field["title"],0,'.
							$titlelen.',"utf-8");
						$field_title="<a href=\''.__APP__.'/news/news_con/id/$id \'>".$field["title"]."</a>";?>
				';//解析H拆字
				$str.=$content;
				$str.="<?php endforeach;?>";
				/*
				echo "<li><a href=\''.__APP__.'/news/news_con/id/'.
						"$id".'\'>".$field["title"]."</a></li>";
				$str.=$content;
				$str.='<?php } ? >';*/
				return $str;
	}else{
			$str="<?php echo '<script>alert(\"此栏目不存在请确认\")</script>';?>";
			return $str;
	}
	}
	} 

	function _images($attr,$content){//图片展示 可指定属性 TABLE NID ORDER BY
		$id=isset($attr['nid'])?$attr['nid']:'';
		if(empty($id)){
			$str="<?php echo '<script>alert(\"请指定Nid属性\")</script>';?>";
			return $str;
		}else{
			$db=M('news');
			$row=$db->where("id='$id'")->find();
			if($db->get_affected_rows()){
				$limit=isset($attr['row'])?$attr['row']:'';
				$by=isset($attr['by'])?$attr['by']:'';
				$str='';
				$str.='<?php $db=M("upload");';
				$str.='$row=$db->where("id=\''.$id.'\'")->limit('.$limit.')->all();';
				$str.='foreach ($row as $field ) {
						$field_url=$field[\'gourl\'];
						$field_src="'.__ROOT__.'/".$field[\'thumb\'];
						$field_des=$field[\'description\'];
					?>';
				$str.=$content;
				$str.='<?php } ?>';
					return $str;
			}
		}
	}
	function _pagelist($attr,$content){
		$catid=isset($attr['cid'])?$attr['cid']:'';
		$row=isset($attr['row'])?$attr['row']:'5';
		$table=isset($attr['table'])?$attr['table']:'news';
		$wherecatid=!empty($catid)?"catid='$catid'":'';
		$str='';
		$str.='<?php $db=M("'.$table.'");';
		$str.='$count=$db->where('.$wherecatid.')->count();';
		$str.='$page=new page($count,'.$row.');';
		$str.='$sql_limit=$page->limit();';
		$str.='$row=$db->limit($sql_limit)->all();';
		$str.='foreach ($row as $field) {
		if(\''.$table.'\'==\'news\')	$field_url="<a href=\''.__CONTROL__.'/news_con/id/".$field["id"]."\'>".$field["title"]."</a>";
			if(\''.$table.'\'==\'upload\') $src="'.__ROOT__.'/".$field["thumb"];
			?>';
		$str.=$content;
		$str.='<?php } ;
		 	echo $page->show(2);?>';
		return $str;
	}
	









	}
	
	 ?>